# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=qtkeychain
pkgver=0.14.1
pkgrel=1
pkgdesc="Qt API to store passwords and other secret data"
url="https://github.com/frankosterfeld/qtkeychain"
arch="all"
license="BSD-2-Clause"
depends="dbus:org.freedesktop.Secrets"
makedepends="
	cmake
	libsecret-dev
	qt5-qttools-dev
	qt6-qttools-dev
	samurai
	"
subpackages="
	$pkgname-dev
	qt5-qtkeychain:qt5
	qt6-qtkeychain:qt6
	qt5-qtkeychain-lang:qt5_lang
	qt6-qtkeychain-lang:qt6_lang
	"
# replace prior names
replaces="qtkeychain qt5-qtkeychain qt5-qtkeychain-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/frankosterfeld/qtkeychain/archive/$pkgver.tar.gz"
options="!check"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi

	export CXXFLAGS="$CXXFLAGS -DNDEBUG -flto=auto"

	cmake -B build-qt5 -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		$CMAKE_CROSSOPTS

	cmake --build build-qt5

	cmake -B build-qt6 -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DBUILD_WITH_QT6=ON \
		$CMAKE_CROSSOPTS

	cmake --build build-qt6
}

package() {
	DESTDIR="$pkgdir" cmake --install build-qt5
	DESTDIR="$pkgdir" cmake --install build-qt6
}

qt5() {
	pkgdesc="$pkgdesc (Qt5)"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/libqt5keychain.so.*
}

qt5_lang() {
	pkgdesc="$pkgdesc (Qt5 translations)"
	install_if="qt5-qtkeychain=$pkgver-r$pkgrel lang"

	amove usr/share/qt5keychain/translations
}

qt6() {
	pkgdesc="$pkgdesc (Qt6)"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/libqt6keychain.so.*
}

qt6_lang() {
	pkgdesc="$pkgdesc (Qt6 translations)"
	install_if="qt6-qtkeychain=$pkgver-r$pkgrel lang"

	amove usr/share/qt6keychain/translations
}

sha512sums="
bf84b19090e667a2946297e63d9813574193d80e4eecbde2fdfca317a66da3f029b3abef326f4ffb32de032a48004f9cf1bc818468af612723d762652dc25eb6  qtkeychain-0.14.1.tar.gz
"
